﻿using Quartz;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using XJay.Identity.Common.Helper;

namespace XJay.Job
{
    public abstract class BaseJob : IJob
    {
        protected IJobExecutionContext jobContext = null;
        public BaseJob()
        {
            string str = AppConfig.ConnectionString;
        }
        
        public async Task Execute(IJobExecutionContext context)
        {
            jobContext = context;
            await TodoJob(context);
        }
        /// <summary>
        /// 要做的Job
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public abstract Task TodoJob(IJobExecutionContext context);

        /// <summary>
        /// 数据库操作对象
        /// </summary>
        public SqlSugarClient XJaySqlClient => new (new ConnectionConfig()
        {
            ConnectionString = AppConfig.ConnectionString,
            DbType = DbType.SqlServer,
            IsAutoCloseConnection = true
        },
           db => {
               //5.1.3.24统一了语法和SqlSugarScope一样，老版本AOP可以写外面

               db.Aop.OnLogExecuting = (sql, pars) =>
               {
                   Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响

                   //5.0.8.2 获取无参数化SQL 对性能有影响，特别大的SQL参数多的，调试使用
                   //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
               };


           });
    }
}
